<template>
  <Header />
  <!-- 主内容区域 -->
  <div class="container">
    <h1 class="page-title">系统功能模块</h1>

    <div class="app-grid">
      <div v-if="checkPermission(Permissions.company, Action.view)" class="app-item"
           @click="navigationTo('/company')">
        <div class="app-icon" style="background: linear-gradient(135deg, #9b59b6, #8e44ad);">
          <i class="fas fa-house"></i>
        </div>
        <div class="app-name">公司管理</div>
      </div>


      <!-- 人员管理 -->
      <div v-if="checkPermission(Permissions.personnel, Action.view)" class="app-item"
           @click="navigationTo('/staff')">
        <div class="app-icon" style="background: linear-gradient(135deg, #3498db, #2980b9);">
          <i class="fas fa-users"></i>
        </div>
        <div class="app-name">人员管理</div>
      </div>

      <!-- 财务管理 -->
      <div v-if="checkPermission(Permissions.finance, Action.view)" class="app-item"
           onclick="location.href='#'">
        <div class="app-icon" style="background: linear-gradient(135deg, #2ecc71, #27ae60);">
          <i class="fas fa-chart-line"></i>
        </div>
        <div class="app-name">财务管理</div>
      </div>


      <div v-if="checkPermission(Permissions.car, Action.view)" class="app-item"
           @click="navigationTo('/car')">
        <div class="app-icon bg-amber">
          <i class="fas fa-car"></i>
        </div>
        <div class="app-name">车辆管理</div>
      </div>

      <div v-if="checkPermission(Permissions.device, Action.view)" class="app-item"
           @click="navigationTo('/device')">
        <div class="app-icon bg-dark">
          <i class="fas fa-camera"></i>
        </div>
        <div class="app-name">物料管理</div>
      </div>


      <div v-if="checkPermission(Permissions.department, Action.view)" class="app-item"
           @click="navigationTo('/department')">
        <div class="app-icon bg-indigo">
          <i class="fas fa-house"></i>
        </div>
        <div class="app-name">部门管理</div>
      </div>
      <!-- 项目管理 -->
      <div v-if="checkPermission(Permissions.project, Action.view)" class="app-item"
           @click="navigationTo('/project')">
        <div class="app-icon" style="background: linear-gradient(135deg, #e74c3c, #c0392b);">
          <i class="fas fa-tasks"></i>
        </div>
        <div class="app-name">项目管理</div>
      </div>

    </div>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import "@fortawesome/fontawesome-free/css/all.min.css"
import {useUserStore} from "../../store/userStore.ts";
import {useMenuStore} from "../../store/menuStore.ts";
import Header from "../../layout/Header.vue";
import {Action, Permissions} from "../../types/permissions.ts";

const router = useRouter();
let {checkPermission} = useUserStore();
let {setActiveIndex} = useMenuStore();


const navigationTo = (path:string) => {
  router.push(path);
  setActiveIndex(path)
}
</script>

<style scoped>


/* 主内容区域 */
.container {
  max-width: 1200px;
  margin: 30px auto;
  padding: 0 20px;
}

.page-title {
  text-align: center;
  margin-bottom: 40px;
  color: #2c3e50;
  font-size: 28px;
}

/* 图标网格布局 */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 30px;
  justify-content: center;
  max-width: 900px;
  margin: 0 auto;
}

.app-item {
  background: white;
  border-radius: 12px;
  padding: 25px 15px;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.app-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.app-icon {
  width: 70px;
  height: 70px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
  font-size: 30px;
  color: white;
}

.app-name {
  font-weight: 600;
  font-size: 16px;
  color: #2c3e50;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .app-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  .logo span {
    display: none;
  }
}

@media (max-width: 480px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .user-name {
    display: none;
  }
}
</style>